#include "Defs.h"
#include "IKeysFilterFunctor.h"
#include "Utils.h"

namespace
{
    NTSTATUS Filter(KeyboardInputData* keysBuf, unsigned int index, unsigned int count)
    {
        ASSERT(index < count);
        void* dst = static_cast<void*>(&keysBuf[index]);
        void* src = static_cast<void*>(&keysBuf[index + 1]);
        memmove(dst, src, (count - index - 1) * sizeof(KeyboardInputData));
        return STATUS_NOT_IMPLEMENTED;
    }
}

NTSTATUS utils::FilterKeyboardInputData(__in KeyboardInputData* keysBuf, unsigned int keysBufSize, __in const IKeysFilterFunctor& filter, unsigned int& newSize)
{
    for(unsigned int i = 0; i < keysBufSize; ++i)
    {
        if(filter(keysBuf[i]))
        {
            CHECK_AND_RETURN(Filter(keysBuf, i, keysBufSize));
            --keysBufSize;
        }
    }
    newSize = keysBufSize;
    return STATUS_SUCCESS;
}
